// $Id: singleton.h 54 2004-10-11 15:31:22Z jonas $
#ifndef SINGLETON_H
#define SINGLETON_H

/**
 * This is a neat template using base class for singleton classes. To use this
 * class, make sure to inherit from "Singleton<YouClassName>" and don't forget
 * to protect you constructor and make this class your friend.
 */
template <typename Type>
class Singleton
{
public:
	virtual ~Singleton() {}

	static Type *getInstance()
	{
		if (!instance) {
			instance = new Type;
		}
		return instance;
	}

	static void cleanUp()
	{
		delete instance;
		instance = 0;
	}

protected:
	Singleton() {}
	static Type *instance;
};

template <typename Type>
Type *Singleton<Type>::instance = 0;

#endif
